import { BaseSubscriber } from "src/database/base/subscriber";
import { PostEntity } from "src/entity/Entity";
import { PostBodyType } from "src/entity/EntityConfig/constants";
import { PostRepository } from "src/entity/repositories";
import { DataSource, EventSubscriber, ObjectType } from "typeorm";
@EventSubscriber()
export class PostSubscriber extends BaseSubscriber<PostEntity>{
    protected entity: ObjectType<PostEntity>;
    constructor(
        protected dataSource: DataSource,
        protected postRepository: PostRepository) {
        super(dataSource)
    }
    listenTo() {
        return PostEntity;
    }
    async afterLoad(entity: PostEntity) {
        if (entity.type === PostBodyType.HTML) {
            entity.body = null
        }
    }
}